package com.framework.modules.dataview.service.impl;

import com.baomidou.mybatisplus.plugins.pagination.Pagination;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.framework.common.utils.PageUtils;
import com.framework.common.utils.Query;

import com.framework.modules.dataview.dao.ViewUserPostsListDao;
import com.framework.modules.dataview.entity.ViewUserPostsListEntity;
import com.framework.modules.dataview.service.ViewUserPostsListService;


@Service("viewUserPostsListService")
public class ViewUserPostsListServiceImpl extends ServiceImpl<ViewUserPostsListDao, ViewUserPostsListEntity> implements ViewUserPostsListService {

    private final List<String> columns= Arrays.asList("adddate");

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        EntityWrapper<ViewUserPostsListEntity> wrapper=new EntityWrapper<ViewUserPostsListEntity>();
        if(params.containsKey("state")){
            wrapper.eq("state",params.get("state"));
        }
        if(params.containsKey("tag")){
            wrapper.eq("tag",params.get("tag").toString());
        }
        if(params.containsKey("type")){
            wrapper.eq("type",params.get("type").toString());
        }
        if(params.containsKey("nickname")){
            wrapper.eq("nickname",params.get("nickname").toString());
        }
        if(params.containsKey("uid")){
            wrapper.eq("uid",params.get("uid"));
        }
        if(params.containsKey("uids")){
            List<String> uids=(List<String>)params.get("uids");
            if(uids.size()==0){
                return new PageUtils(new Page<ViewUserPostsListEntity>());
            }
            wrapper.in("uid",uids);
        }
        if(params.containsKey("viewPolicys")){
            List<String> viewPolicys=(List<String>)params.get("viewPolicys");
            wrapper.in("view_policy",viewPolicys);
        }
        Page<ViewUserPostsListEntity> page = this.selectPage(
                new Query<ViewUserPostsListEntity>(params).getPage(),
                wrapper.orderDesc(columns)
        );

        return new PageUtils(page);
    }

    @Override
    public List<ViewUserPostsListEntity> getViewUserPostsList(Pagination page, Map<String, Object> para) {
        return this.baseMapper.getViewUserPostsList(page,para);
    }

}
